package com.dkd.manage.controller;

import com.dkd.common.annotation.Log;
import com.dkd.common.core.domain.R;
import io.swagger.annotations.*;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.dkd.common.core.controller.BaseController;
import com.dkd.common.core.domain.AjaxResult;
import com.dkd.manage.domain.TaskDetails;
import com.dkd.manage.service.ITaskDetailsService;
import com.dkd.common.utils.poi.ExcelUtil;
import com.dkd.common.core.page.TableDataInfo;

/**
 * 工单详情Controller
 *
 * @author han
 * @date 2025-03-28
 */
@RestController
@RequestMapping("/manage/taskDetails")
@Api(value = "TaskDetailsController", tags = {"工单详情管理"})
public class TaskDetailsController extends BaseController
{
    @Autowired
    private ITaskDetailsService taskDetailsService;

    /**
     * 查询工单详情列表
     */
    @PreAuthorize("@ss.hasPermi('manage:details:list')")
    @GetMapping("/list")
    @ApiOperation(value = "查询工单详情列表", notes = "分页查询工单详情列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页码", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "每页数量", dataType = "int", paramType = "query"),
            // 添加其他需要的查询参数注释
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "成功", response = TableDataInfo.class)
    })
    public TableDataInfo list(TaskDetails taskDetails)
    {
        startPage();
        List<TaskDetails> list = taskDetailsService.selectTaskDetailsList(taskDetails);
        return getDataTable(list);
    }

    /**
     * 查看工单补货详情
     */
    @PreAuthorize("@ss.hasPermi('manage:taskDetails:list')")
    @GetMapping(value = "/byTaskId/{taskId}")
    @ApiOperation(value = "查看工单补货详情", notes = "根据任务ID查询工单补货详情")
    @ApiImplicitParam(name = "taskId", value = "任务ID", dataType = "Long", required = true, paramType = "path")
    @ApiResponses({
            @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    })
    public R<List<TaskDetails>> byTaskId(@PathVariable("taskId") Long taskId) {
        TaskDetails taskDetailsParam = new TaskDetails();
        taskDetailsParam.setTaskId(taskId);
        return R.ok(taskDetailsService.selectTaskDetailsList(taskDetailsParam));
    }

    /**
     * 导出工单详情列表
     */
    @PreAuthorize("@ss.hasPermi('manage:details:export')")
    @Log(title = "工单详情", businessType = com.dkd.common.enums.BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation(value = "导出工单详情列表", notes = "导出工单详情列表到Excel")
    @ApiImplicitParams({
            // 添加导出功能需要的查询参数注释
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "文件下载")
    })
    public void export(HttpServletResponse response, TaskDetails taskDetails)
    {
        List<TaskDetails> list = taskDetailsService.selectTaskDetailsList(taskDetails);
        ExcelUtil<TaskDetails> util = new ExcelUtil<>(TaskDetails.class);
        util.exportExcel(response, list, "工单详情数据");
    }

    /**
     * 获取工单详情详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:details:query')")
    @GetMapping(value = "/{detailsId}")
    @ApiOperation(value = "获取工单详情详细信息", notes = "根据详情ID获取工单详情信息")
    @ApiImplicitParam(name = "detailsId", value = "详情ID", dataType = "Long", required = true, paramType = "path")
    @ApiResponses({
            @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    })
    public AjaxResult getInfo(@PathVariable("detailsId") Long detailsId)
    {
        return success(taskDetailsService.selectTaskDetailsByDetailsId(detailsId));
    }

    /**
     * 新增工单详情
     */
    @PreAuthorize("@ss.hasPermi('manage:details:add')")
    @Log(title = "工单详情", businessType = com.dkd.common.enums.BusinessType.INSERT)
    @PostMapping
    @ApiOperation(value = "新增工单详情", notes = "新增工单详情信息")
    @ApiImplicitParam(name = "taskDetails", value = "工单详情信息", dataType = "TaskDetails", required = true, paramType = "body")
    @ApiResponses({
            @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    })
    public AjaxResult add(@RequestBody TaskDetails taskDetails)
    {
        return toAjax(taskDetailsService.insertTaskDetails(taskDetails));
    }

    /**
     * 修改工单详情
     */
    @PreAuthorize("@ss.hasPermi('manage:details:edit')")
    @Log(title = "工单详情", businessType = com.dkd.common.enums.BusinessType.UPDATE)
    @PutMapping
    @ApiOperation(value = "修改工单详情", notes = "修改工单详情信息")
    @ApiImplicitParam(name = "taskDetails", value = "工单详情信息", dataType = "TaskDetails", required = true, paramType = "body")
    @ApiResponses({
            @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    })
    public AjaxResult edit(@RequestBody TaskDetails taskDetails)
    {
        return toAjax(taskDetailsService.updateTaskDetails(taskDetails));
    }

    /**
     * 删除工单详情
     */
    @PreAuthorize("@ss.hasPermi('manage:details:remove')")
    @Log(title = "工单详情", businessType = com.dkd.common.enums.BusinessType.DELETE)
    @DeleteMapping("/{detailsIds}")
    @ApiOperation(value = "删除工单详情", notes = "根据详情ID数组删除工单详情信息")
    @ApiImplicitParam(name = "detailsIds", value = "详情ID数组", dataType = "Long[]", required = true, paramType = "path")
    @ApiResponses({
            @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    })
    public AjaxResult remove(@PathVariable Long[] detailsIds)
    {
        return toAjax(taskDetailsService.deleteTaskDetailsByDetailsIds(detailsIds));
    }
}